package com.sx.zongzhi.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;

import com.sx.zongzhi.BaseActivity;
import com.sx.zongzhi.R;
import com.sx.zongzhi.adapter.SpinnerPubAdapter;
import com.sx.zongzhi.bean.EconomicOrganizionBean;
import com.sx.zongzhi.bean.GlobalBean;
import com.sx.zongzhi.bean.MsgEvent;
import com.sx.zongzhi.bean.PublicBean;
import com.sx.zongzhi.presenter.PublicListPest;
import com.sx.zongzhi.utils.MyRxBus;
import com.sx.zongzhi.utils.ToastUtils;
import com.sx.zongzhi.view.IPublicBeanView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 搜索非公有制经济组织
 * Created by admin on 2017/12/9.
 */

public class EconomicOrganizationSearchActivity extends BaseActivity implements IPublicBeanView {

    @BindView(R.id.et_licenseNumber)
    EditText etLicenseNumber;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.sp_style)
    Spinner spStyle;
    @BindView(R.id.et_residence)
    EditText etResidence;
    @BindView(R.id.et_enterpriseMobile)
    EditText etEnterpriseMobile;
    @BindView(R.id.et_enterpriseTelephone)
    EditText etEnterpriseTelephone;
    @BindView(R.id.et_chief)
    EditText etChief;
    @BindView(R.id.et_mobileNumber)
    EditText etMobileNumber;
    @BindView(R.id.et_telephone)
    EditText etTelephone;
    @BindView(R.id.et_chiefSafe)
    EditText etChiefSafe;
    @BindView(R.id.et_mobileNumberSafe)
    EditText etMobileNumberSafe;
    @BindView(R.id.et_telephoneSafe)
    EditText etTelephoneSafe;

    private List<GlobalBean> style;

    @Override
    public void setUI(Bundle savedInstanceState) {
        setContentView(R.layout.activity_sear_economic);
        setTitleName("非公有制经济组织搜索");
        ButterKnife.bind(this);
        setTitleRight("确定");
        new PublicListPest(this).getPublicList("新经济组织类别");
    }

    @OnClick({R.id.tv_right})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.tv_right:
                subMit();
                break;
        }
    }
    private void subMit() {
        EconomicOrganizionBean bean = new EconomicOrganizionBean();

        bean.setLicenseNumber(etLicenseNumber.getText().toString().trim());
        bean.setName(etName.getText().toString().trim());
        bean.setResidence(etResidence.getText().toString().trim());
        bean.setSearchStyleId(((GlobalBean)spStyle.getSelectedItem()).getId());
        bean.setEnterpriseMobile(etEnterpriseMobile.getText().toString().trim());
        bean.setEnterpriseTelephone(etEnterpriseTelephone.getText().toString().trim());
        bean.setChief(etChief.getText().toString().trim());
        bean.setMobileNumber(etMobileNumber.getText().toString().trim());
        bean.setTelephone(etTelephone.getText().toString().trim());
        bean.setChiefSafe(etChiefSafe.getText().toString().trim());
        bean.setMobileNumberSafe(etMobileNumberSafe.getText().toString().trim());
        bean.setTelephoneSafe(etTelephoneSafe.getText().toString().trim());

        MyRxBus.get().post(new MsgEvent("EconomicOrganizationActivity", 2, bean));
        finish();
    }

    @Override
    public void getPublicList(PublicBean publicBean) {
        if ("新经济组织类别".equals(publicBean.getDomainName())) {
            style = publicBean.getDicts();
            if (style != null) {
                SpinnerPubAdapter adapter = new SpinnerPubAdapter(this, R.layout.item_text, style);
                spStyle.setAdapter(adapter);
            }
        }
    }

    @Override
    public void showError(String message) {
        ToastUtils.showToast(EconomicOrganizationSearchActivity.this, message);
    }
}
